from variable import *

def copyATPreportafter():
    # 7. copy术后服务报告到术后文件夹，更改拷贝至MailWork_path
    os.chdir(MailWork_path)
    key = "ATP2术后报告模板"
    if os.path.exists(Report_BasicPath):
        print(Report_BasicPath + " exitst")
        for root, dirs, files in os.walk(Report_BasicPath):
            if root == Report_BasicPath:  # 限定在Report_BasicPath下遍历文件
                for file in files:
                    if key in file:
                        # print('找到包含"' + key + '"字符的文件,绝对路径为----->' + Report_BasicPath + '/' + file)
                        # print('复制到----->' + MailWork_path + "/" + file)
                        src_file = os.path.join(root, file)
                        shutil.copy(src_file, MailWork_path)
    #   重命名文件
    if not os.path.isfile(ServiceReport_NameAfter):
        os.rename(src_file, ServiceReport_NameAfter)
    #   删除源文件
    if os.path.exists(MailWork_path + "/" + "ATP2术后报告模板.xlsx"):
        os.remove(MailWork_path + "/" + "ATP2术后报告模板.xlsx")
        print('移除后术后目录下有文件：%s' % os.listdir(MailWork_path))
    else:
        print("要删除的文件不存在！")
    pass